

cmake_minimum_required(VERSION 3.8...3.15 FATAL_ERROR)

#强制外部编译
if($PROJECT_BINARY_DIR} STREQUAL $PROJECT_SOURCE_DIR})
  message(FATAL_ERROR "源码路径和构建路径不能相同，请创建build文件夹；需要手动删除CMakeFiles/ 和 CMakeCache.txt")
endif()

# 名称
set(_NAME H2O2)
project (${_NAME})
set(CMAKE_CXX_STANDARD 17)

# 引入模块路径
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake)

# 从文本中读取版本号
file(STRINGS version.txt _version)
message(STATUS "当前版本：${_version}")

#提取版本号
include(DetermineVersion)
extract_version_components("${_version}" ${_NAME})
message(STATUS "当前版本：${${_NAME}_VERSION}")

# 设置include 目录
if (NOT DEFINED _INSTALL_INCLUDE_DIR)
  set(_INSTALL_INCLUDE_DIR "include/${_NAME}-${${_NAME}_VERSION_MAJOR}.${${_NAME}_VERSION_MINOR}")
endif()
if (NOT DEFINED _INSTALL_CONFIG_DIR)
  set(_INSTALL_CONFIG_DIR "lib/cmake/${_NAME}-${${_NAME}_VERSION_MAJOR}.${${_NAME}_VERSION_MINOR}")
endif()
if (NOT DEFINED _INSTALL_LIB_DIR)
  set(_INSTALL_LIB_DIR "lib")
endif()
if (NOT DEFINED _INSTALL_BIN_DIR)
  set(_INSTALL_BIN_DIR "bin")
endif()
if (NOT DEFINED _INSTALL_SHARE_DIR)
  set(_INSTALL_SHARE_DIR "share/${_NAME}-${${_NAME}_VERSION_MAJOR}.${${_NAME}_VERSION_MINOR}")
endif()
if (NOT DEFINED _INSTALL_CMAKE_MODULE_DIR)
  set(_INSTALL_CMAKE_MODULE_DIR "${_INSTALL_SHARE_DIR}/cmake")
endif()
if (NOT DEFINED _BUILD_CMAKE_BASE_DIR)
  set(_BUILD_CMAKE_BASE_DIR "${VTKm_BINARY_DIR}")
endif()
if(NOT DEFINED _EXECUTABLE_OUTPUT_PATH)
  ## Set the directory where the binaries will be stored
  set(_EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
endif()
if(NOT DEFINED _LIBRARY_OUTPUT_PATH)
  ## Set the directory where the libraries will be stored
  set(_LIBRARY_OUTPUT_PATH  ${PROJECT_BINARY_DIR}/lib)
endif()
if (NOT DEFINED _EXPORT_NAME)
  set(_EXPORT_NAME "VTKmTargets")
endif()

set(_BINARY_INCLUDE_DIR "${VTKm_BINARY_DIR}/include")

# 第三方依赖选项设置
option(ENABLE_MPI "开启MPI" OFF)
option(ENABLE_CUDA "开启GPU" OFF)
option(ENABLE_TESTING "测试用例可用" OFF)
option(ENABLE_PETSC "开启petsc库" OFF)
option(ENABLE_METIS "开启metis" OFF)
mark_as_advanced(
    ENABLE_CUDA
    ENABLE_PETSC
)

# 设置构建类型
include(BuildType)

include(CompilerFlags)
# include(Wrappers)
add_subdirectory(contrib/timpi)
add_subdirectory(src)

add_subdirectory(examples/introduction/ex5)